package org.luxor.cloud.authentication.component.handler;

import org.luxor.commons.security.handler.AbstractAuthenticationFailureEvenHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.stereotype.Component;

/**
 * 登录失败事件处理器
 *
 * @author Mr.Yan  @date: 2020/9/18
 */
@Component
public class AuthenticationFailureEvenHandler extends AbstractAuthenticationFailureEvenHandler {
    private static final Logger logger = LoggerFactory.getLogger(AuthenticationFailureEvenHandler.class);

    /**
     * 处理登录失败事件
     *
     * @param authentication          失败原因
     * @param authenticationException 登录对象
     */
    @Override
    public void handle(AuthenticationException authenticationException, Authentication authentication) {
        logger.info("用户[{}] 登录失败. 原因:{}", authentication.getPrincipal(), authenticationException.getLocalizedMessage());
    }
}
